package deposit.main;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

public abstract class Deposit implements InterestInterface, Serializable {
    public final double ZERO = 0.0;
    public final double INTEREST_MINIMAL_VALUE = -1.0;
    
    protected String bank;
    protected String depoId;
    protected Date startDate;
    protected int dayLong;
    protected double sum;
    protected double interestRate;
    protected double interest;

    public Deposit() {
	this.interest = INTEREST_MINIMAL_VALUE;
    }

    public Deposit(String bank, String depoId, Date startDate, int dayLong,
	    double sum, double interestRate) {
	this.bank = bank;
	this.depoId = depoId;
	this.startDate = startDate;
	this.dayLong = dayLong;
	this.sum = sum;
	this.interestRate = interestRate;
	this.interest = INTEREST_MINIMAL_VALUE;
    }

    protected int getDaysInDepositYear() {
	GregorianCalendar calendar = new GregorianCalendar();
	calendar.setTime(startDate);
	GregorianCalendar yearEnd = new GregorianCalendar(calendar.get(Calendar.YEAR), Calendar.DECEMBER, 31);
	int ret = yearEnd.get(Calendar.DAY_OF_YEAR)- calendar.get(Calendar.DAY_OF_YEAR);
	calendar.add(GregorianCalendar.YEAR, 1);
	ret += calendar.get(Calendar.DAY_OF_YEAR);
	return ret;
    }

    public String getBank() {
	return bank;
    }

    public void setBank(String bank) {
	this.bank = bank;
    }

    public String getDepoId() {
	return depoId;
    }

    public void setDepoId(String depoId) {
	this.depoId = depoId;
    }

    public Date getStartDate() {
	return startDate;
    }

    public void setStartDate(Date startDate) {
	this.startDate = startDate;
    }

    public int getDayLong() {
	return dayLong;
    }

    public void setDayLong(int dayLong) {
	this.dayLong = dayLong;
    }

    public double getSum() {
	return sum;
    }

    public void setSum(double sum) {
	this.sum = sum;
    }

    public double getInterestRate() {
	return interestRate;
    }

    public void setInterestRate(double interestRate) {
	this.interestRate = interestRate;
    }
    
//    public static final double getSumDeposits(List<Deposit> deposits){
//	double sum = 0.0;
//	for (Deposit d : deposits) {
//	    if (d instanceof SimpleDeposit) {
//		SimpleDeposit sd = (SimpleDeposit) d;
//		sum += sd.getInterest();
//		System.out.println(sd.getInterest());
//	    }
//
//	    if (d instanceof MonthCapitalizeDeposit) {
//		MonthCapitalizeDeposit mcd = (MonthCapitalizeDeposit) d;
//		sum += mcd.getInterest();
//		System.out.println(mcd.getInterest());
//	    }
//	}
//	return sum;
//    }
    
    
}